package com.fyzk.betcode.klpk;

import android.text.Spanned;

import com.fyzk.activity.lottery.gaopin.K3Activity;
import com.fyzk.activity.lottery.shuzicai.BallInfo;
import com.fyzk.betcode.CodeBase;

import java.util.List;

public class KLPKBaoXuanBetCode extends CodeBase{

	private int indext = 0;
	private int baoXuanId = 0;
	private String baoXuanNum = "07";

	public KLPKBaoXuanBetCode(int indext, int baoXuanId) {
		this.indext = indext;
		this.baoXuanId = baoXuanId;
	}

	@Override
	public String betCode(List<List<BallInfo>> balls) {
		// TODO Auto-generated method stub
		StringBuffer strB = new StringBuffer();
		String sanTongHaoTongXuan = "";
		List<BallInfo> infos = balls.get(indext);
		for(int j = 0 ; j < infos.size(); j ++){
			BallInfo info = infos.get(j);
			if(j != infos.size() - 1 && info.isSelected()){
				strB.append(codeZhuanHuan(info.getNum()));
				strB.append("^");
			}
			if (j == infos.size() - 1 && info.isSelected()) {
				baoXuanNum = info.getNum();
				sanTongHaoTongXuan = "^!"+ baoXuanId+"-"+info.getNum();
			}
		}
		if(strB.length()>0){//去除多余的“,”
			strB.deleteCharAt(strB.length()-1);
		}
		
		strB.append(sanTongHaoTongXuan);
		if (strB.toString().equals("^!"+baoXuanId+"-1")) {
			return baoXuanNum;
		}else{
			return strB.toString();
		}
		
	}

	@Override
	public String showCode() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	@Deprecated
	public Spanned formatHtmlCode(String code) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String formatHtmlCode2(String code) {//zhuMa: 06,07,03,06,03

		// TODO Auto-generated method stub
		
		if (code.contains("^!"+baoXuanId+"-"+baoXuanNum)) {
			code = code.substring(0, code.length() - 10);
			code += ";三同号通选";
		}else if (code.equals("1")) {
			code = "三同号通选";
		}
		
		String betNums = getGv_Infos2(code);
		
		betNums = "<font color=\"#ff0000\">" + betNums + "</font>" + " ";
		
		String htmlStr ="<html><body>"+ betNums + "</body></html>";
		
		return htmlStr;
	}
	
	private String getGv_Infos2(String num){
		if (!num.equals("") && num.contains(",")) {
			num = num.replace(",", "");
		}
		
		if (!num.equals("") && num.contains("^")) {
			num = num.replace("^", ",");
		}
		return num;
	}
	
	private String codeZhuanHuan(String code){
		String newCode = "";
		for (int i = 0; i < code.length(); i++) {
			newCode += code.charAt(i) + ",";
		}
		
		if (newCode.length() > 0) {
			newCode = newCode.substring(0, newCode.length() - 1);
		}
		return newCode;
	}

}
